function [A_t, M_t, BI_t, Nbar_i, HH_bin, CollPerc_t, Pol_t, Own_t, Inc_t, tract_nerc_xxwalk, tract_state_xxwalk, distance_border, tract_border_xxwalk, population]=read_tract_data3()

global PropTax IncTax SalesTax


title='../Data/CleanedData/PropTax.csv';
 PropTax= readmatrix(title); 


title='../Data/CleanedData/IncTax.csv';
 IncTax= readmatrix(title); 

 title='../Data/CleanedData/SalesTax.csv';
 SalesTax= readmatrix(title); 


title='../Data/CleanedData/tract.csv';
 tract= readmatrix(title); 

tract_state_xxwalk_temp=floor(tract/(10E8));

%convert statefips to index
tract_state_xxwalk=zeros(size(tract));
count=1; 
for i=1:100
    if sum(tract_state_xxwalk_temp==i)>0
       tract_state_xxwalk(tract_state_xxwalk_temp==i)=count;
       count=count+1;
    end
end

title='../Data/CleanedData/A_t.csv';
A_t=readmatrix(title);

title='../Data/CleanedData/population.csv';
population=readmatrix(title);

title='../Data/CleanedData/M_t.csv'; %M_t is panels
M_t=readmatrix(title);

title='../Data/CleanedData/BI_t.csv'; % BI is buildings
BI_t=readmatrix(title);


title='../Data/CleanedData/CollPerc_t.csv'; % College perc. Normalized to mean 0
CollPerc_t=readmatrix(title);

title='../Data/CleanedData/Pol_t.csv'; % Dem perc. Normalized to mean 0
Pol_t=readmatrix(title);

title='../Data/CleanedData/Owner_t.csv'; % owner occupied perc. Normalized to mean 0
Own_t=readmatrix(title);
%Own_t=zeros(size(Pol_t));


title='../Data/CleanedData/Inc_t.csv'; % owner occupied perc. Normalized to mean 0
Inc_t=readmatrix(title);

title='../Data/CleanedData/nerc_code.csv'; % owner occupied perc. Normalized to mean 0
tract_nerc_xxwalk=readmatrix(title);


title='../Data/CleanedData/border.csv'; % owner occupied perc. Normalized to mean 0
tract_border_xxwalk=readmatrix(title);

title='../Data/CleanedData/distance.csv'; % owner occupied perc. Normalized to mean 0
distance_border=readmatrix(title);

ntract=size(A_t,1);


%read in bins of number of panels. N_i is number of panel slots.  HH_bin in #
%households in each bin. \
title='../Data/CleanedData/install_size_kw_buckets.csv';
install_size_kw_buckets=readtable(title);

bindata_temp=install_size_kw_buckets;

Nbar_i=zeros(ntract, 1);

HH_bin=zeros(ntract, 1);

for n_i=1:ntract
    if strcmp('', table2array(bindata_temp(n_i,1)))==0 % if row is not blank
        temp=jsondecode(char(table2array(bindata_temp(n_i,1))));
        [x , y]=size(temp);
        for x_i=1:x
            if temp(x_i,1)<42 %42 KW is the 99.9th percentile of array size in TTS. 99: 18KW. 99.99: 400KW
             Nbar_i(n_i,x_i)=4*(temp(x_i,1) + 2.5); % these are allocated dynamically. Which is maybe a bit slow. 2.5 for bin midpoint and times 4 since its in KW (so 250 watts per panel)
             HH_bin(n_i,x_i)=temp(x_i,2);
            end
        end
    end
end


Nbar_i(isnan(Nbar_i))=0;
HH_bin(isnan(HH_bin))=0;

N_t=sum(HH_bin.*Nbar_i,2);
M_t(M_t>N_t)=N_t(M_t>N_t);

HH_t= sum(HH_bin,2);
BI_t(BI_t>HH_t)=HH_t(BI_t>HH_t);



